package action.RDD基本转换操作4

import org.apache.spark.{SparkConf, SparkContext}

/**
  * def intersection(other: RDD[T]): RDD[T]
  * def intersection(other: RDD[T], numPartitions: Int): RDD[T]
  * def intersection(other: RDD[T], partitioner: Partitioner)(implicit ord: Ordering[T] = null): RDD[T]
  *
  * 该函数返回两个RDD的交集，并且去重。
  * 参数numPartitions指定返回的RDD的分区数。
  * 参数partitioner用于指定分区函数
  *
  * @author wdmcode@aliyun.com
  * @version 1.0.0
  * @date 2018/11/8
  */
object SparkIntersection {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName("SparkParallelize")
    conf.setMaster("local[2]")

    val spark = new SparkContext(conf)

    val rdd = spark.parallelize(1 to 2)

    val rdd2 = spark.parallelize(2 to 3)

    val rddUnion = rdd.intersection(rdd2)

    // rddUnion: Array[Int] = Array(1, 2, 3)
  }
}
